/*
package com.iris.live.services.data.repositories.impl;

import com.google.common.collect.Maps;
import com.iris.live.services.common.StringUtils;
import com.iris.live.services.data.models.TGroupUserItemModel;
import com.iris.live.services.data.repositories.GroupUserRepository;
import com.iris.live.services.models.PageData;
import com.iris.live.services.services.GroupUserService;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

*/
/**
 * @author: wangzhenyan
 * date: 2017/9/26 9:57
 *//*

@Repository
public class GroupUserRepositoryImpl extends BaseRepository implements GroupUserRepository {

    @Override
    public List getGroupRoles() {
        String sql = "select roleName from lsh_group_role_map";
        return this.getList(sql);
    }

    @Override
    public PageData getGroupUsers(GroupUserService.GroupUserRequest userRequest) {
        StringBuffer sql = new StringBuffer("SELECT  " +
                "   a.许可, " +
                "   b.ACCOUNT_NAME `用户名`,  " +
                "   a.`人员姓名`,   " +
                "   a.`人员电话`,   " +
                "   c.departmentName 所属部门,   " +
                "   a.角色 管理范围, " +
                "   case a.角色 when '大区' then a.许可 when 'PMA' then (select distinct 大区 from lsh经销商表 where cta = a.许可) else '' end 大区, " +
                "   case a.角色 when 'PMA' then a.许可 else '' end PMA, " +
                "   a.更新日期, " +
                "   a.kpi使用状态, " +
                "   case a.disabledStatus when '1' then '停用' else '启用' end 启用状态, " +
                "   a.group_position_cn, " +
                "   a.group_position_en " +
                "FROM `用户` a " +
                "join T_ACCOUNT_INFO b on a.ACCOUNT_ID = b.ACCOUNT_ID " +
                "left join t_group_department c on a.所属部门 = c.id " +
                "WHERE a.ACCOUNT_ID = b.ACCOUNT_ID  " +
                "and userType = '1' ");
//                "and a.许可 = :permit ");

        Map params = new HashMap();
//        params.put("permit", userRequest.permit);
        if (!StringUtils.isNullOrBlank(userRequest.username)) {
            sql.append("and b.account_name like :username ");
            params.put("username","%" + userRequest.username + "%");
        }
        if (!StringUtils.isNullOrBlank(userRequest.realname)) {
            sql.append("and a.人员姓名 like :realname ");
            params.put("realname","%" + userRequest.realname + "%");
        }
        if (!StringUtils.isNullOrBlank(userRequest.mobile)) {
            sql.append("and a.人员电话 like :mobile ");
            params.put("mobile","%" + userRequest.mobile + "%");
        }
        if (!StringUtils.isNullOrBlank(userRequest.roleType)) {
            sql.append("and a.角色 = :roleType ");
            params.put("roleType",userRequest.roleType);
        }
        return this.getPage(sql.toString(),params,userRequest.getPageSize(),userRequest.getPageIndex());
    }

    @Override
    public List getRoleDepartmentRelationMap() {
        String sql = "select rolename as 管理范围,departmentname 所属部门 " +
                "from lsh_group_role_map a ,t_group_department b,t_group_roledepartment c " +
                "where a.id=c.grouproleid and b.id=c.groupdepartmentid ";
        return this.getList(sql);
    }

    @Override
    public List getAllGroupItems() {
        String sql = "select * from t_group_iteminfo order by sort asc";
        return this.getList(sql);
    }

    @Override
    public List getUserGroupItems(GroupUserService.GroupItemsRequest params) {
        String sql = "select a.*   " +
                "  from t_group_iteminfo a  " +
                "  join t_group_useritem b on a.id=b.itemid  " +
                "  join t_account_info d on b.username = d.ACCOUNT_NAME " +
                "  join `用户` c on d.ACCOUNT_ID = c.account_id " +
                "  where b.permission = c.许可 " +
                "  and d.ACCOUNT_NAME = :userName " +
                "  and c.许可 = :permit";
        Map map = new HashMap();
        map.put("permit",params.permit);
        map.put("userName",params.userName);
        return this.getList(sql,map);
    }

    @Override
    public List getDepartItems(GroupUserService.GroupItemsRequest params) {
        String sql = "select a.*  " +
                "from t_group_iteminfo a " +
                "join t_group_depart_item_init b on a.id=b.itemid " +
                "join t_group_department c on b.departid = c.id " +
                "where c.departmentname = :departmentName";
        Map map = new HashMap();
        map.put("departmentName",params.departmentName);
        return this.getList(sql,map);
    }

    @Override
    public int deleteGroupUserItems(String permit, String userName) {
        String sql = "delete from t_group_useritem where permission = :permit and userName = :userName ";
        Map params = Maps.newHashMap();
        params.put("permit",permit);
        params.put("userName",userName);
        return this.executeUpdate(sql,params);
    }

    @Override
    public int saveGroupUserItems(TGroupUserItemModel itemModel) {
        String sql = "insert into t_group_useritem(permission,username,itemId) values(:permit,:userName,:itemId) ";
        Map params = Maps.newHashMap();
        params.put("permit",itemModel.getPermission());
        params.put("userName",itemModel.getUserName());
        params.put("itemId",itemModel.getItemId());
        return this.executeUpdate(sql,params);
    }

    @Override
    public List getGroupDepartment(String departmentName) {
        String sql = " select * from t_group_department where departmentName = :departmentName ";
        Map params = Maps.newHashMap();
        params.put("departmentName",departmentName);
        return this.getList(sql,params);
    }

    @Override
    public int updateUserPwd(Integer accountId,String password) {
        String sql = "update 用户 a set a.密码 = :password where a.account_id = :accountId";
        Map params = new HashMap();
        params.put("accountId",accountId);
        params.put("password",password);
        return this.executeUpdate(sql,params);
    }
}
*/
